package com.qfedu.provider.controller;

import com.qfedu.config.SystemConfig;
import com.qfedu.parm.LoginCodeParam;
import com.qfedu.parm.UserAdd;
import com.qfedu.parm.UserLogin;
import com.qfedu.provider.service.DbUserService;
import com.qfedu.utils.R;
import com.qfedu.vo.UserFind;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 * @date 2024/11/23 上午11:17
 */
@RestController
@RequestMapping("/server/user")
@Tag(name = "用户模块")
@Slf4j
@RequiredArgsConstructor
public class UserController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    // private final DbUserService service;

    @Resource
    private DbUserService dbUserService;

    /*
     * param:request:获取请求头中的ip(唯一性登录)
     * */
    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public R register(@RequestBody UserAdd user) {
        return dbUserService.register(user);
    }

    @Operation(summary = "用户登录--密码登录")
    @PostMapping("/loginpass")
    public R login(@RequestBody UserLogin user) {
        return dbUserService.loginpass(user );
    }

    @Operation(summary = "发送短信验证码")
    @PostMapping("/sendcode")
    public R sendcode(String phone) {
        return dbUserService.sendcode(phone);
    }

    @PostMapping
    @Operation(summary = "用户登录--短信登录")
    public R login(@RequestBody LoginCodeParam parm) {
        return dbUserService.logincode(parm );
    }

    @PostMapping("/findpass")
    @Operation(summary = "找回密码")
    public R findpass(@RequestBody UserFind userFind) {
        return dbUserService.findpass(userFind);
    }

    @GetMapping("/logout")
    @Operation(summary = "退出登录")
    public R logout(HttpServletRequest request) {
        return dbUserService.logout(request.getHeader(SystemConfig.TOKEN));

    }
}
